#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define in read()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

int read() {
	int x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

const int N = 20;
const int S = 1 << N;

int f[S + 10][2], cnt[S + 10], val[S + 10], n, Q, U;
char s[S + 10];

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in, Q = in, U = 1 << n; U--;
	scanf("%s", s);
	rep(i, 0, U) val[i] = f[i][0] = f[i][1] = s[i] - '0';
	rep(i, 0, n - 1)
		rep(j, 0, U)
		if(j >> i & 1)
			f[j ^ (1 << i)][0] += f[j][0], f[j][1] += f[j ^ (1 << i)][1];
	rep(i, 1, U) cnt[i] = cnt[i ^ (i & -i)] + 1;
	while(Q--) {
		scanf("%s", s);
		int s0 = 0, s1 = 0, s2 = 0;
		rep(i, 0, n - 1)
			if(s[n - i - 1] == '0') s0 |= 1 << i;
			else if(s[n - i - 1] == '1') s1 |= 1 << i;
			else s2 |= 1 << i;
		int ans = 0;
		if(cnt[s0] <= n / 3) {
			for(int t = s0; ; t = (t - 1) & s0) {
				ans += f[t | s1][0] * (cnt[t] & 1 ? -1 : 1); if(t == 0) break;
			}
		} else if(cnt[s1] <= n / 3) {
			for(int t = s1; ; t = (t - 1) & s1) {
				ans += f[t | s2][1] * (cnt[t ^ s1] & 1 ? -1 : 1); if(t == 0) break;
			}
		} else {
			for(int t = s2; ; t = (t - 1) & s2) {
				ans += val[t | s1]; if(t == 0) break;
			}
		} printf("%d\n", ans);
	}
	return 0;
}
